//package com.example.sale.Interceptor;
//
//import com.example.sale.True.Verification;
//import org.springframework.amqp.core.ExchangeTypes;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class RabbitMqListener {
//    @Autowired
//    private StringRedisTemplate stringRedisTemplate;
//    @RabbitListener(queues = "test.queue2")
//    public void MqListener(String msg){
//        System.out.println("消费者0收到了test.queue2的消息"+msg);
//    }
//    //这是两个消费者一起消费
//    @RabbitListener(queues = "work.queue")
//    public void ListerWorkQueue(String msg) throws InterruptedException {
//        System.out.println("消费者1收到了work.queue的消息"+msg);
//        Thread.sleep(20);
//    }
//    @RabbitListener(queues = "work.queue")
//    public void ListerWorkQueue2(String msg) throws InterruptedException {
//        System.out.println("消费者2收到了work.queue的消息"+msg);
//        Thread.sleep(100);
//    }
//    //
//    @RabbitListener(queues = "fanout.queue1")
//    public void ListerFanoutQueue(String msg) throws InterruptedException {
//        System.out.println("消费者1收到了fanout.queue1的消息"+msg);
//    }
//    @RabbitListener(queues = "fanout.queue2")
//    public void ListerFanoutQueue2(String msg) throws InterruptedException {
//        System.out.println("消费者2收到了fanout.queue2的消息"+msg);
//    }
//    //消息监听
////    @RabbitListener(bindings = @QueueBinding(
////            value = @Queue(name = "direct.queue1",durable = "true"),
////            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT),
////            key = {"red","blue"}
////    ))
////    public void ListerDirectQueue(String msg) throws InterruptedException {
////        System.out.println("消费者1收到了direct.queue1的消息"+msg);
////    }
////    @RabbitListener(bindings = @QueueBinding(
////            value = @Queue(name = "direct.queue2",durable = "true"),
////            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT),
////            key = {"red","yellow"}
////    ))
////    public void ListerDirectQueue2(String msg) throws InterruptedException {
////        System.out.println("消费者2收到了direct.queue2的消息"+msg);
////    }
//    //消息监听topic交换机
//    @RabbitListener(queues = "topic.queue1")
//    public void ListerTopicQueue(String msg) throws InterruptedException {
//        System.out.println("消费者1收到了topic.queue1的消息"+msg);
//    }
//    @RabbitListener(queues = "topic.queue2")
//    public void ListerTopicQueue2(String msg) throws InterruptedException {
//        System.out.println("消费者2收到了topic.queue2的消息"+msg);
//    }
//    @RabbitListener(queues = "object.queue1")
//    public void ListerObjectQueue1(Map<String,Object> msg) throws InterruptedException {
//        System.out.println("消费者2收到了topic.queue2的消息"+msg);
//    }
//    //生成验证码的所有的队列
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.qq",durable = "true"),
//            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT),
//            key = {"red","green"}
//    ))
//    public void ListerDirectQueue(Verification verification) throws InterruptedException {
//        System.out.println("消费者1收到了来自qq验证码的存储消息"+verification.getKey() +"信息是"+verification.getVscode());
//        stringRedisTemplate.opsForValue().set(verification.getKey(),verification.getVscode(),60, TimeUnit.SECONDS);
//    }
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.phone",durable = "true"),
//            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT),
//            key = {"blue"}
//    ))
//    public void ListerDirectQueue2(Verification verification) throws InterruptedException {
//        stringRedisTemplate.opsForValue().set(verification.getKey(),verification.getVscode(),300, TimeUnit.SECONDS);
//        System.out.println("消费者2收到了来自手机验证码的存储消息"+verification.getKey() + "消息是"+verification.getVscode());
//    }
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.main",durable = "true"),
//            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT),
//            key = {"yellow","green"}
//    ))
//    public void ListerDirectQueue3(Verification verification) throws InterruptedException {
//        stringRedisTemplate.opsForValue().set(verification.getKey(),verification.getVscode(),60, TimeUnit.SECONDS);
//        System.out.println("消费者3收到了主页存储的验证码的消息"+verification.getKey()+ "消息是"+verification.getVscode());
//    }
//}
